#include <unistd.h>
#include <cstdlib>
#include <time.h>

#include "queue.hpp"
#include "task.hpp"
using namespace cp_task;
using namespace cp_queue;
void* consumer(void* args){
  pthread_detach(pthread_self());
  queue<Task>* q = (queue<Task>*)args;
  while(1){
    Task t;
    q->pop(&t);
    t.run();
  }
}
void* producter(void* args){
  pthread_detach(pthread_self());
  queue<Task>* q = (queue<Task>*)args;
  std::string ops = "+-*/%";
  while(1){
    sleep(1);
    int x = rand() % 20 + 1;
    int y = rand() % 10 + 1;
    char op = ops[rand() % 5];
    Task t(x, y, op);
    q->push(t);
  }
}
int main(){
  srand((long long)time(nullptr));
  queue<Task>* q = new queue<Task>();

  pthread_t c, p;
  pthread_create(&c, nullptr, consumer, (void*)q);//消费者线程
  pthread_create(&p, nullptr, producter, (void*)q);//生产者线程

  sleep(100);
  //pthread_join(c, nullptr);
  //pthread_join(p, nullptr);
  return 0;
}
